import axios from 'axios';
import Config from '../config/config.js';
// import store from '../vuex/store.js';
import {getToken} from './auth.js';
var $http = axios.create({
  baseURL: Config.api,
  timeout: 5000,
});
// axios配置
$http.interceptors.request.use(config => {
    config.headers.common['Authorization'] = 'Bearer' + getToken();
    return config;
}, error => {
    // Do something with request error
    return Promise.reject(error);
});
// 响应拦截
$http.interceptors.response.use(response => {
    return response;
}, error => {
    if(error.response) {
        // 微信网页授权认证失败
        if(error.response.status == 401) {
            console.log(error);
        }
        // 需要登录的接口，跳转到登录注册页面
        if(error.response.status == 402) {
            console.log(error);
        }
    } else {

    }
    return Promise.reject(error);
});
export { $http };